libxl: un-constify return value of libxl_basename
authorWei Liu <wei.liu2@citrix.com>
Mon, 1 Dec 2014 11:31:12 +0000 (11:31 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 2 Dec 2014 13:55:28 +0000 (13:55 +0000)
The string returned is malloc'ed but marked as "const".

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/libxl/libxl.h
tools/libxl/libxl_utils.c
tools/libxl/libxl_utils.h

index 41d6e8db6c0f5df9211eaf1d2e2a9045d6f2a2ab..291c1909f9ec6e23e13380d245e42d741628c109 100644 (file)
@@ -477,6 +477,16 @@ typedef struct libxl__ctx libxl_ctx;
 #define LIBXL_HAVE_NONCONST_EVENT_OCCURS_EVENT_ARG 1
 #endif
 
+/*
+ * LIBXL_HAVE_CONST_LIBXL_BASENAME_RETURN_VALUE
+ *
+ * The return value of libxl_basename is malloc'ed but the erroneously
+ * marked as "const" in releases before 4.5.
+ */
+#if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x040500
+#define LIBXL_HAVE_CONST_LIBXL_BASENAME_RETURN_VALUE 1
+#endif
+
 /*
  * LIBXL_HAVE_PHYSINFO_OUTSTANDING_PAGES
  *
index 3e1ba170bd15e84840c0b108ef23538b6ee727ef..22119fcb8a57af4d5de2a6ab2687b6000dd95b2d 100644 (file)
 
 #include "libxl_internal.h"
 
-const char *libxl_basename(const char *name)
+#ifdef LIBXL_HAVE_CONST_LIBXL_BASENAME_RETURN_VALUE
+const
+#endif
+char *libxl_basename(const char *name)
 {
     const char *filename;
     if (name == NULL)
index 117b22924c3ca59ccf4b4a26b94a1ece75817c10..8277eb9ec91c8d23a2f2dafee809ef856bc70527 100644 (file)
 
 #include "libxl.h"
 
-const char *libxl_basename(const char *name); /* returns string from strdup */
+#ifdef LIBXL_HAVE_CONST_LIBXL_BASENAME_RETURN_VALUE
+const
+#endif
+char *libxl_basename(const char *name); /* returns string from strdup */
+
 unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, unsigned int smp_cpus);
 int libxl_name_to_domid(libxl_ctx *ctx, const char *name, uint32_t *domid);
 int libxl_domain_qualifier_to_domid(libxl_ctx *ctx, const char *name, uint32_t *domid);